﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace RPN
{
    /// <summary>
    /// Логика взаимодействия для MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        RevPNotation rpn;
        
        public MainWindow()
        {
           
            InitializeComponent();
             rpn = new RevPNotation();
             
            
        }
       
        private void button1_Click(object sender, RoutedEventArgs e)
        {

            rpn.InputString += "1";
            textBox1.Text += "1";
            
           
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
          //  rpn.InputString = textBox1.Text;
            textBox1.Text = rpn.Calculate().ToString();
        }

        private void button3_Click(object sender, RoutedEventArgs e)
        {
            rpn.InputString += "2";
            textBox1.Text += "2";
            
        }

        private void button18_Click(object sender, RoutedEventArgs e)
        {
            rpn.InputString += "3";
            textBox1.Text += "3";
            
        }

        private void button14_Click(object sender, RoutedEventArgs e)
        {
            rpn.InputString += " / ";
            textBox1.Text += "/";
            
        }

        private void button13_Click(object sender, RoutedEventArgs e)
        {
            rpn.InputString += " - ";
            textBox1.Text += "-";
            
        }

        private void button5_Click(object sender, RoutedEventArgs e)
        {
            rpn.InputString += "4";
            textBox1.Text += "4";
            
        }

        private void button7_Click(object sender, RoutedEventArgs e)
        {
            rpn.InputString += "5";
            textBox1.Text += "5";
            
        }

        private void button6_Click(object sender, RoutedEventArgs e)
        {
            rpn.InputString += "6";
            textBox1.Text += "6";
            
        }

        private void button4_Click(object sender, RoutedEventArgs e)
        {
            rpn.InputString += "7";
            textBox1.Text += "7";
            
        }

        private void button9_Click(object sender, RoutedEventArgs e)
        {
            rpn.InputString += "8";
            textBox1.Text += "8";
            
        }

        private void button8_Click(object sender, RoutedEventArgs e)
        {
            rpn.InputString += "9";
            textBox1.Text += "9";
           
        }

        private void button10_Click(object sender, RoutedEventArgs e)
        {
            rpn.InputString += "0";
            textBox1.Text += "0";
           
        }

        private void button15_Click(object sender, RoutedEventArgs e)
        {
            rpn.InputString += " * ";
            textBox1.Text += "*";
            
        }

        private void button11_Click(object sender, RoutedEventArgs e)
        {
            rpn.InputString += " + ";
            textBox1.Text += "+";
            
        }

        private void button12_Click(object sender, RoutedEventArgs e)
        {
            rpn.InputString += ",";
            textBox1.Text += ",";
            
        }

        private void button17_Click(object sender, RoutedEventArgs e)
        {
            rpn.InputString += " ( ";
            textBox1.Text += "(";
            
        }

        private void button19_Click(object sender, RoutedEventArgs e)
        {
            rpn.InputString += " ) ";
            textBox1.Text  += ")";
            
        }

        private void button20_Click(object sender, RoutedEventArgs e)
        {
            rpn.Clear();
            textBox1.Text = "";
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
          
            // TODO добавить проверку на знаки операций
            if (e.Key < Key.D0 || e.Key > Key.D9)
            {
                // Determine whether the keystroke is a number from the keypad.
                if (e.Key < Key.NumPad0 || e.Key > Key.NumPad9)
                {
                    if (e.Key != Key.Decimal)
                    {
                        // Determine whether the keystroke is a backspace.
                        if (e.Key != Key.Back)
                        {
                            e.Handled = true;
                        }
                    }
                }
            }

            if (e.Key == Key.Enter)
            {
                 this.Title = "WPFCalc";
                rpn.InputString = textBox1.Text;
                //вывод решения
                textBox1.Text = rpn.Calculate().ToString();
            }
            
        }

        
    }
}
